﻿using System.Text.RegularExpressions;

namespace AudioSourceManager
{
    internal class URLReader
    {
        public string IP = "";
        public int Port = 0;
        public string Protocol = "";

        public URLReader(string iP, int port, string protocol)
        {
            IP = iP;
            Port = port;
            Protocol = protocol;
        }

        public static bool TryResolve(string url, out URLReader reader)
        {
            string pattern = @"^(?<protocol>\w+):\/\/@(?<address>[^:]+)(?::(?<port>\d+))?";
            reader = null;
            Match match = Regex.Match(url, pattern);
            if (match.Success)
            {
                string IP = match.Groups["address"].Value;
                int.TryParse(match.Groups["port"].Value, out int Port);
                string Protocol = match.Groups["protocol"].Value;
                reader = new URLReader(IP, Port, Protocol);
                return true;
            }
            return false;
        }
    }
}
